package com.zxl.always.on.display.ui.helper;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.zxl.always.on.display.ui.activity.KeepLiveActivity;

/**
 * Created by Administrator on 2018/2/24.
 */

public class WindowHelper {

    private WindowManager windowManager;

    private WindowManager.LayoutParams windowParams;

    public WindowHelper(Context context) {
        windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, 65794, -2);
    }

    public void add(View view) {
        try {
            windowManager.addView(view, windowParams);
            KeepLiveActivity.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void remove(View view) {
        try {
            windowManager.removeView(view);
            KeepLiveActivity.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
